<template>
	<view>

	</view>
</template>

<script>
	import {
		Config
	} from '../../common/Config.js'
	export default {
		data() {
			return {
				token: '',
			}
		},
		onLoad(options) {
			let that = this;
			console.log(options);
			uni.showLoading({
				title: '返回数据中'
			});
			if(options.token){
				that.token = options.token;
				uni.setStorageSync('userToken', options.token);
				that.getUserInfo();
			}
			// if(options.device.trim() && options.port.trim()){
			// 	that.device = options.device;
			// 	that.port = options.port;
			// 	uni.setStorageSync('userToken', options.token);
			// 	uni.redirectTo({
			// 		url: '../poweron/poweron?device=' + options.device + '&port=' + options.port +
			// 			'&cmd=' + 0 + '&from=' + 1,
			// 	});
			// }
			// else{
			// 	that.appKey = options.appKey;
			// 	uni.setStorageSync('userToken', options.token);
			// 	uni.redirectTo({
			// 		url: '../smcharging/smcharging',
			// 	});
			// }
		},
		methods: {
			getUserInfo() {
				let that = this;
				that.$base.request('user/userInfo', 'GET')
					.then(res => {
						if (res.data.code == 200) {
							that.userlist = res.data.data
							that.userlist.id = that.pad(that.userlist.id, 8)
							uni.setStorageSync('user', that.userlist)
							uni.setStorageSync('phone', that.userlist.phone)
							uni.setStorageSync('Name', that.userlist.realName)
							if (res.data.data.subscribe == 0) {
								uni.redirectTo({
									url: '/pages/qr_code/qr_code'
								})
								return
							}
							else{
								uni.reLaunch({
									url: '/pages/smcharging/smcharging'
								})
							}
						}
						else{
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}
					})
					.catch(err => {
				
					})
			},
			
			pad(num, n) {
				var len = num.toString().length;
				while (len < n) {
					num = "0" + num;
					len++;
				}
				return num;
			},

		},
	}
</script>

<style>

</style>